home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-15 | 9.9 KB | 345 lines | [TEXT/CWIE] |
- {This file was processed by Dan's Source Converter}
- {version 1.3 (this version modified by Ingemar Ragnemalm)}
-
- {09-15-96 Should be working now}
- {Matt Mora fixed some porting bugs}
- {mxmora@apple.com}
-
- program BoxShell;
-
- uses
- Types, QuickDraw, Events, Windows, Dialogs, Fonts, DiskInit, TextEdit, Traps,{}
- Memory, SegLoad, Scrap, ToolUtils, OSUtils, Menus, Resources, StandardFile,{}
- GestaltEqu, Files, Errors, Devices, QuickDrawText, TextUtils, {}
-
- {End of standard head. Add more units to uses as necessary.}
-
- { BoxShell.c - QuickDraw 3d routines}
- {}
- { This is box, the QuickDraw 3D starter program. Written for the}
- { Getting started with QuickDraw 3D Develop article. This app does not have }
- { graceful error handling - it's putpose is to illustrate a very basic QuickDraw }
- { 3D program.}
- {}
- { Nick Thompson - January 6th 1995}
- { }
- { ©1994-95 Apple computer Inc., All Rights Reserved}
- {}
-
- { system headers}
- PictUtils, QDOffScreen,
-
- { for QuickDraw 3D}
- QD3D, QD3DMath, QD3DDrawContext, QD3DShader, QD3DTransform, QD3DGroup, QD3DStyle, QD3DView, Box3DSupport;
-
- const
- mApple = 128;
- mFile = 129;
- mEdit = 130;
- mTest = 131;
-
- const
- iAbout = 1;
-
- const
- iNew = 1;
- iOpen = 2;
- iClose = 3;
- iUnused1 = 4;
- iQuit = 5;
-
- {-------------------------------------------------------------------------------------------}
- {}
- const
- iUsePictPalette = 1;
-
- {-------------------------------------------------------------------------------------------}
- { constants - defined in SmallShell.c}
- var
- kRGBBlack: RGBColor;
- kRGBWhite: RGBColor;
-
- {-------------------------------------------------------------------------------------------}
-
- type
- _documentRecord = record
- fView: TQ3ViewObject; { the view for the scene}
- fModel: TQ3GroupObject; { object in the scene being modelled}
- fInterpolation: TQ3StyleObject; { interpolation style used when rendering}
- fBackFacing: TQ3StyleObject; { whether to draw shapes that face away from the camera}
- fFillStyle: TQ3StyleObject; { whether drawn as solid filled object or decomposed to components}
- fRotation: TQ3Matrix4x4; { the transform for the model}
- end;
-
- type
- DocumentRec = _documentRecord;
- DocumentPtr = ^DocumentRec;
- DocumentHdl = ^DocumentPtr;
-
- {-------------------------------------------------------------------------------------------}
- {}
-
- var
- gQuitFlag: Boolean;
- gMainWindow: WindowPtr;
- gDocument: DocumentRec;
- dummyStatus: TQ3Status;
-
- {-------------------------------------------------------------------------------------------}
- {}
-
- {-------------------------------------------------------------------------------------------}
- procedure InitDocumentData (theDocument: DocumentPtr);
- {-------------------------------------------------------------------------------------------}
- var
- dummyMatrix: TQ3Matrix4x4Ptr;
- { sets up the 3d data for the scene}
- { Create view for QuickDraw 3D.}
- begin
- theDocument^.fView := MyNewView(gMainWindow);
-
- { the main display group:}
- theDocument^.fModel := MyNewModel;
-
- { the drawing styles:}
- theDocument^.fInterpolation := Q3InterpolationStyle_New(kQ3InterpolationStyleNone);
- theDocument^.fBackFacing := Q3BackfacingStyle_New(kQ3BackfacingStyleBoth);
- theDocument^.fFillStyle := Q3FillStyle_New(kQ3FillStyleFilled);
-
- { set the rotation matrix the identity matrix}
- dummyMatrix := Q3Matrix4x4_SetIdentity(theDocument^.fRotation);
- end;
-
- {-------------------------------------------------------------------------------------------}
- procedure DisposeDocumentData (theDocument: DocumentPtr);
- {-------------------------------------------------------------------------------------------}
-
- begin
- if theDocument^.fView <> nil then
- begin
- dummyStatus := Q3Object_Dispose(theDocument^.fView); { the view for the scene}
- end;
- dummyStatus := Q3Object_Dispose(theDocument^.fModel); { object in the scene being modelled}
- dummyStatus := Q3Object_Dispose(theDocument^.fInterpolation); { interpolation style used when rendering}
- dummyStatus := Q3Object_Dispose(theDocument^.fBackFacing); { whether to draw shapes that face away from the camera}
- dummyStatus := Q3Object_Dispose(theDocument^.fFillStyle); { whether drawn as solid filled object or decomposed to components}
-
- end;
-
- {-------------------------------------------------------------------------------------------}
- function DocumentDraw3DData (theDocument: DocumentPtr): TQ3Status;
- {-------------------------------------------------------------------------------------------}
- begin
- if theDocument^.fView <> nil then
- begin
-
- dummyStatus := Q3View_StartRendering(theDocument^.fView);
- repeat
- dummyStatus := Q3Style_Submit(theDocument^.fInterpolation, theDocument^.fView);
- dummyStatus := Q3Style_Submit(theDocument^.fBackFacing, theDocument^.fView);
- dummyStatus := Q3Style_Submit(theDocument^.fFillStyle, theDocument^.fView);
- dummyStatus := Q3MatrixTransform_Submit(theDocument^.fRotation, theDocument^.fView);
- dummyStatus := Q3DisplayGroup_Submit(theDocument^.fModel, theDocument^.fView);
- until not (Q3View_EndRendering(theDocument^.fView) = kQ3ViewStatusRetraverse);
- DocumentDraw3DData := kQ3Success;
- end
- else
- begin
- DocumentDraw3DData := kQ3Failure;
- end;
-
- end;
-
-
- {-------------------------------------------------------------------------------------------}
- function HiWrd (aLong: LongInt): Integer;
- {-------------------------------------------------------------------------------------------}
- begin
- HiWrd := Point(aLong).v;
- end;
-
- {-------------------------------------------------------------------------------------------}
- function LoWrd (aLong: LongInt): Integer;
- {-------------------------------------------------------------------------------------------}
- begin
- LoWrd := Point(aLong).h;
- end;
-
- {-------------------------------------------------------------------------------------------}
- procedure InitToolbox;
- {-------------------------------------------------------------------------------------------}
- begin
- MaxApplZone;
- MoreMasters;
- MoreMasters;
- MoreMasters;
-
- InitGraf(@qd.thePort);
- InitFonts;
- InitWindows;
- InitCursor;
-
- FlushEvents(everyEvent, 0);
- { initialize application globals}
-
- gQuitFlag := false;
-
- end;
-
- {-------------------------------------------------------------------------------------------}
- procedure HandleKeyPress (var event: EventRecord);
- {-------------------------------------------------------------------------------------------}
- begin
- end;
-
- {-------------------------------------------------------------------------------------------}
- procedure RotateCube(window:WindowRef);
- {-------------------------------------------------------------------------------------------}
- var
- tmp: TQ3Matrix4x4;
- theRect: Rect;
- dummyMatrix: TQ3Matrix4x4Ptr;
- begin
- theRect := gMainWindow^.portRect;
- SetPort(gMainWindow);
- dummyMatrix := Q3Matrix4x4_SetRotate_XYZ(tmp, 0.1, 0.12, 0.08);
- dummyMatrix := Q3Matrix4x4_Multiply(gDocument.fRotation, tmp, gDocument.fRotation);
-
- InvalRect(theRect);
- end;
-
- {-------------------------------------------------------------------------------------------}
- procedure MainEventLoop;
- {-------------------------------------------------------------------------------------------}
-
- var
- event: EventRecord;
- window: WindowPtr;
- thePart: Integer;
- screenRect, updateRect: Rect;
- aPoint: Point;
- savedPort: CGrafPtr;
-
- begin
-
- aPoint.h := 100;
- aPoint.v := 100;
-
- while not gQuitFlag do
- begin
-
- if WaitNextEvent(everyEvent, event, 0, nil) then
- begin
- case (event.what) of
- mouseDown:
- begin
- thePart := FindWindow(event.where, window);
-
- case thePart of
- inMenuBar:
- ;
-
- inDrag:
- begin
- screenRect := GetGrayRgn^^.rgnBBox;
- DragWindow(window, event.where, screenRect);
- end;
-
- inContent:
- if (window <> FrontWindow) then
- SelectWindow(window);
-
- inGoAway:
- if (TrackGoAway(window, event.where)) then
- begin
- DisposeWindow(window);
- gQuitFlag := true;
-
- end;
-
- otherwise
-
- end; {case}
- end; {mouseDown}
-
-
- updateEvt:
- begin
- window := WindowPtr(event.message);
- updateRect := window^.visRgn^^.rgnBBox;
- SetPort(window);
- BeginUpdate(window);
- dummyStatus := DocumentDraw3DData(@gDocument);
- EndUpdate(window);
- end;
-
- keyDown, autoKey:
- HandleKeyPress(event);
-
- diskEvt:
- if (HiWrd(event.message) <> noErr) then
- if DIBadMount(aPoint, event.message) <> noErr then
- ;
-
- osEvt, activateEvt:
- ;
-
-
- end;
- RotateCube(window);
- end
- else
- { we received a null event, rotate the cube}
-
- begin
- RotateCube(window);
- end;
-
- end;
- end;
-
-
-
- {-------------------------------------------------------------------------------------------}
- { main()}
- {-------------------------------------------------------------------------------------------}
- { entry point for the application, initialize the toolbox, initialize QuickDraw 3D}
- { and enter the main event loop. On exit from the main event loop, we want to call}
- { the QuickDraw 3D exit function to clean up QuickDraw 3d.}
-
- {main}
-
- var
- myStatus: TQ3Status;
- rBounds: Rect;
- const
- title = 'Spinning Box (Pascal)';
-
- begin
- InitToolbox;
-
- SetRect(rBounds, 50, 50, 450, 450);
-
- { Initialize QuickDraw 3D, open a connection to the QuickDraw 3D library}
- myStatus := Q3Initialize;
-
- if (myStatus = kQ3Failure) then
- DebugStr('ErInitialize returned failure.');
-
- { set up our globals}
- gQuitFlag := false;
- gMainWindow := NewCWindow(nil, rBounds, title, true, noGrowDocProc, WindowPtr(-1), true, 0);
-
- InitDocumentData(@gDocument);
-
- MainEventLoop;
-
- DisposeDocumentData(@gDocument);
-
- { Close our connection to the QuickDraw 3D library}
- myStatus := Q3Exit;
- if (myStatus = kQ3Failure) then
- DebugStr('ErExit returned failure.');
-
- end.
-